/*
 * @Author: liyin 2179253556@qq.com
 * @Date: 2023-04-28 16:42:59
 * @LastEditors: liyin 2179253556@qq.com
 * @LastEditTime: 2025-07-11 15:08:31
 * @FilePath: index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { ElMessage, ElMessageBox } from 'element-plus'
export const PiniaStore = defineStore('pcmain', {
    state: () => {
        return {
            isCollapse: false,
            tableHeight: 0,
            searchHeight: 0,
            innerHeight: window.innerHeight / 2,
            showPagition: true,
            searchShow: true,
            mainHeight: 0,
            pageQuery: {
                page: 1,
                page_size: 20
            },
            visitedRoutes: [] as any,
            schoolList: [] as any,
            hasLeftSide: false,
            isShowContent: true,
            previewInfo: {
                home_page_data: [],
                group_page_data: []
            },
            zoom: 1,
            outerVisible: false,
        }
    },
    persist: {
        key: 'pcmain',
        storage: window.sessionStorage
    },
    actions: {
        setOuterVisible(bol: boolean) {
            this.outerVisible = bol;
        },
        setCollapse(params: any) {
            this.isCollapse = params
        },
        setHasLeftSide(params: any) {
            this.hasLeftSide = params
        },
        setShowContent(bol: boolean) {
            this.isShowContent = bol
        },
        setPageQueryPage(params: any, count?: boolean) {
            if (count) {
                this.pageQuery.page += params
            } else {
                this.pageQuery.page = params
            }
        },
        setPageQueryPageSize(params: any) {
            this.pageQuery.page_size = params
        },
        setZoom(val: number) {
            this.zoom = val
            console.log(val)
        },
        // 初始化pa{ge组件
        setRefreshPage() {
            this.pageQuery.page = 1
            this.pageQuery.page_size = 20
        },
        // 没有搜索框
        setTableHeight2() {
            this.tableHeight = (window.innerHeight - this.searchHeight * this.zoom - 285 * this.zoom) / this.zoom
        },
        // 获取表格的高度
        setTableHeight() {
            this.tableHeight = (window.innerHeight - this.searchHeight * this.zoom - 279 * this.zoom) / this.zoom
        },
        // 记录search高度
        setSearchHeight(params: any) {
            console.log(window.innerHeight)
            this.searchHeight = params
            this.tableHeight = (window.innerHeight - params * this.zoom - 285 * this.zoom) / this.zoom
        },
        // 判断是否需要呈现pagition组件，为了解决keep-alive问题
        setShowPagition(params: boolean) {
            this.showPagition = params
        },
        setMainHeight(params: number) {
            this.mainHeight = params
        },
        //  记录search 的查询框条数
        setSearchCount(bol?: boolean) {
            console.log(bol)
            if (bol !== null && bol !== undefined) {
                this.searchShow = bol
            } else {
                this.searchShow = !this.searchShow
            }
        },
        // 存储路由
        setVisitedRoutes(item?: any) {
            this.visitedRoutes.push(item)
        },
        // 存储首页配置数据
        setHomePageData(item: any) {
            this.previewInfo.home_page_data = item
            sessionStorage.setItem("previewInfo", JSON.stringify(this.previewInfo))
        },
        setGroupPageData(item: any) {
            this.previewInfo.group_page_data = item
            sessionStorage.setItem("previewInfo", JSON.stringify(this.previewInfo))
        }
    }
})